﻿using System;
using System.Collections.Generic;
using System.Text;
using Stauffware.Common.Core;
using Stauffware.Common.Time;
using System.Globalization;
using NUnit.Framework;

namespace UnitTests.Time
{
	class DateParseTests
	{
		//=============================================================================

		[TestFixtureSetUp]
		public static void SetUp()
		{
			IFormatProvider ifp = CultureInfo.CurrentCulture;
			System.Console.WriteLine("CultureInfo.CurrentCulture is " + ifp.GetType().FullName);
		}

		//=============================================================================
		// positive testcases for date-only parsing

		//							year   mon  day		
		[TestCase("12/31/2199",		2199,	12, 31,		DateParseOptions.ParseEntireInput, null)]
		[TestCase("1/1/1754",		1754,	1,	1,		DateParseOptions.ParseEntireInput, null)]
		[TestCase("3/29/2017",		2017,	3,	29,		DateParseOptions.ParseEntireInput, null)]
	//	[TestCase("29/3/2017",		2017,	3,	29,		DateParseOptions.ParseEntireInput, null)]
	//	[TestCase("4/3/2017",		2017,	3,	4,		DateParseOptions.ParseEntireInput, null
		[TestCase("3/29/2017",		2017,	3,	29,		DateParseOptions.ParseEntireInput, null)]
		[TestCase("3/4/2017",		2017,	3,	4,		DateParseOptions.ParseEntireInput, null)]

		[TestCase("13jan2010",		2010,	1,	13,		DateParseOptions.ParseEntireInput, null)]
		[TestCase("13-jan-2010",	2010,	1,	13,		DateParseOptions.ParseEntireInput, null)]
		[TestCase("13/jan/2010",	2010,	1,	13,		DateParseOptions.ParseEntireInput, null)]
		[TestCase("13 jan 2010",	2010,	1,	13,		DateParseOptions.ParseEntireInput, null)]

		[TestCase("jan-13-2010",	2010,	1,	13,		DateParseOptions.ParseEntireInput, null)]
		[TestCase("jan/13/2010",	2010,	1,	13,		DateParseOptions.ParseEntireInput, null)]
		[TestCase("jan 13 2010",	2010,	1,	13,		DateParseOptions.ParseEntireInput, null)]

		[TestCase("2010-jan-13",	2010,	1,	13,		DateParseOptions.ParseEntireInput, null)]
		[TestCase("2010/jan/13",	2010,	1,	13,		DateParseOptions.ParseEntireInput, null)]
		[TestCase("2010 jan 13",	2010,	1,	13,		DateParseOptions.ParseEntireInput, null)]

		[TestCase("13-1-2010",	2010,	1,	13,		DateParseOptions.ParseEntireInput, null)]
		[TestCase("13/1/2010",	2010,	1,	13,		DateParseOptions.ParseEntireInput, null)]
		[TestCase("13 1 2010",	2010,	1,	13,		DateParseOptions.ParseEntireInput, null)]

		[TestCase("1-13-2010",	2010,	1,	13,		DateParseOptions.ParseEntireInput, null)]
		[TestCase("1/13/2010",	2010,	1,	13,		DateParseOptions.ParseEntireInput, null)]
		[TestCase("1 13 2010",	2010,	1,	13,		DateParseOptions.ParseEntireInput, null)]

		[TestCase("2010-1-13",	2010,	1,	13,		DateParseOptions.ParseEntireInput, null)]
		[TestCase("2010/1/13",	2010,	1,	13,		DateParseOptions.ParseEntireInput, null)]
		[TestCase("2010 1 13",	2010,	1,	13,		DateParseOptions.ParseEntireInput, null)]

		public static void ValueTest (string input, int year, int month, int day, 
											DateParseOptions options, string purpose)
		{
			DateParser parser = new DateParser(options);

			DateParse dp = parser.Parse(input);

			System.Console.WriteLine(ErrorUtils.ValueToString(dp));

			NUnit.Framework.Assert.AreEqual(null, dp.ErrorMessage, "ErrorMessage");
			NUnit.Framework.Assert.AreEqual(true, dp.GotValue, "GotValue");
			NUnit.Framework.Assert.AreEqual(false, dp.IsError, "IsError");
			NUnit.Framework.Assert.AreEqual(false, dp.IsEmpty, "IsEmpty");
			NUnit.Framework.Assert.AreEqual(year, dp.Value.Year, "Year");
			NUnit.Framework.Assert.AreEqual(month, dp.Value.Month, "Month");
			NUnit.Framework.Assert.AreEqual(day, dp.Value.Day, "Day");
		}

		//=============================================================================
		// negative testcases for date parsing
		// The test results must be manually verified for the proper error message.

	//	[TestCase("3/4/1987",	DateParseOptions.ParseEntireInput)]
		[TestCase("2/30/1987",	DateParseOptions.ParseEntireInput)]
		[TestCase("25/3",		DateParseOptions.ParseEntireInput)]

		public static void ErrorTest (string input, DateParseOptions options)
		{
			DateParser parser = new DateParser(options);
			DateParse dp = parser.Parse(input);

			System.Console.WriteLine(dp.ToString());

			NUnit.Framework.Assert.AreEqual(false, dp.GotValue, "GotValue");
			NUnit.Framework.Assert.AreEqual(true, dp.IsError, "IsError");
			NUnit.Framework.Assert.AreEqual(false, dp.IsEmpty, "IsEmpty");
		}

		//=============================================================================
		// Tests that yield "empty".
		//
		//         input     parsed text    options 

	//	[TestCase("",		"",		DateParseOptions.None)]
	//	[TestCase("  ",		"",		DateParseOptions.None)]
		[TestCase("",		"",		DateParseOptions.ParseEntireInput)]

		public static void EmptyTest (string input,
									string expectedParsedText,
									DateParseOptions options)
		{
			DateParser parser = new DateParser(options);
			DateParse dp = parser.Parse(input);

			System.Console.WriteLine(dp.ToString());

			NUnit.Framework.Assert.AreEqual(expectedParsedText, dp.ParsedText, "ParsedText");
			NUnit.Framework.Assert.AreEqual(null, dp.ErrorMessage, "ErrorMessage");
			NUnit.Framework.Assert.AreEqual(false, dp.GotValue, "GotValue");
			NUnit.Framework.Assert.AreEqual(false, dp.IsError, "IsError");
			NUnit.Framework.Assert.AreEqual(true, dp.IsEmpty, "IsEmpty");
		}

		//=============================================================================
	}
}
